package com.kajespero.dao.commons.impl;

import java.util.Collection;
import java.util.Map;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.kajespero.dao.commons.ReadDAO;
import com.kajespero.vo.IdentifierVO;

public abstract class AbstractReadDAO<T extends IdentifierVO<I>, I extends Comparable<I>> extends AbstractDAO<T> implements ReadDAO<T, I> {

	@Override
	public T find(I identifier) {
		return getIntance().find(getBeanClass(), identifier);
	}

	@Override
	public Collection<T> findAll() {
		return getIntance().findAll(getBeanClass());
	}
	
	@Override
	public T findBy(Map<String, Object> values) {
		return getIntance().findBy(getBeanClass(), values);
	}

	@Override
	public Long nextId() {
		Long max = getIntance().lastIdentifier(getBeanClass());
		max = max +1;
		return max;
	}
	
	@Override
	public Key createKey(I id) {
		Long identifier = new Long(id.toString());
		Key key = KeyFactory.createKey(getBeanClass().getSimpleName(), identifier);
		return key;
	}
	
	

}
